﻿/*
 * This software is the confidential and proprietary
 * information of NetBay
 * Such confidential information should not be disclosed
 * NetBay copyright(c) 2010
 */

#region Using 
using System.Collections.Generic;
using System;
using System.DirectoryServices;
using System.Runtime.Serialization;
using System.ComponentModel.DataAnnotations;
using NetBay.Core.BusinessEntities.Barcodes;
using System.Configuration;

#endregion

namespace NetBay.Core.BusinessEntities.ActiveDirectory.Objects
{

    [KnownType(typeof(AdUser))]
    [KnownType(typeof(AdGroup))]
    [DataContract]
    [Serializable]
    public abstract class AdObject : IEntity
    {
        /// <summary>
        /// Gets or sets the key id.
        /// </summary>
        /// <value>The key id.</value>
        [DataMember]
        [Key]
        public Guid KeyId { get; set; }

        /// <summary>
        /// Gets or sets the key id.
        /// </summary>
        /// <value>The key id.</value>
        [DataMember]
        public Guid ForeignKey1 { get; set; }

        /// Gets or sets the type of AdObject.
        /// </summary>
        /// <value>The type of AdObject.</value>
        [DataMember]
        public abstract AdObjectType TypeOfAdObject{ get; set; }


        /// Gets or sets the type of AdObject.
        /// </summary>
        /// <value>The type of AdObject.</value>
        [DataMember]
        public abstract Guid GuidOfAdObject { get; set; }

        /// <summary>
        /// String Information name
        ///  </summary>
        [DataMember]
        public abstract string InformationName { get; }

        /// <summary>
        /// String for the rio User Interface.
        ///  </summary>
        private string _DisplayName;
        [DataMember]
        public string DisplayName
        {
            get { return _DisplayName; }
            set {_DisplayName = value; }
        }

        /// <summary>
        /// Gets or sets the user Ad error.
        /// </summary>
        /// <value>The user error.</value>
        [DataMember]
        public Boolean UserAdError { get; set; }

        /// <summary>
        /// Gets or sets the user Information Ad error.
        /// </summary>
        /// <value>The user information error.</value>
        [DataMember]
        public string UserDisplayAdError { get; set; }
        
        /// <summary>
        /// Sets the foreign key.
        /// </summary>
        /// <param name="p_ieCollection">The p_ie collection.</param>
        /// <param name="p_strKey">The P_STR key.</param>
        public void SetForeignKey1(IEnumerable<IEntity> p_ieCollection, Guid p_strKey)
        {
            foreach (IEntity l_ieItem in p_ieCollection)
            {
                l_ieItem.ForeignKey1 = p_strKey;
            }
        }

        [DataMember]
        public long MappedGroupIdentifier { get; set; }

        [DataMember]
        public string AdName { get; set; }
    }


    /// <summary>
    /// This class represents a LDAP User
    /// </summary>
    [DataContract]
    public class AdUser : AdObject
    {

        #region Private members

        /// <summary>
        /// The LDAP type of object
        /// </summary>
        private AdObjectType e_AdObjectType = AdObjectType.User;

        /// <summary>
        /// The LDAP Guid of the user
        /// </summary>
        private Guid m_gGuid = Guid.NewGuid();
        
        /// <summary>
        /// is the User enabled
        /// </summary>
        private bool m_bEnable = false;
        /// <summary>
        /// The login of the user
        /// </summary>
        private string m_sLogin = string.Empty;
        /// <summary>
        /// The Name of the user
        /// </summary>
        private string m_sName = string.Empty;
        /// <summary>
        /// The FirstName of the user
        /// </summary>
        private string m_sFirstName = string.Empty;
        /// <summary>
        /// The emai of the user
        /// </summary>
        private string m_sEmail = string.Empty;

        #endregion

        #region Properties

        [DataMember]
        public bool Enable
        {
            get { return m_bEnable; }
            set { m_bEnable = value; }
        }

        [DataMember]
        public string Login
        {
            get { return m_sLogin; }
            set { m_sLogin = value; }
        }

        [DataMember]
        public string Name
        {
            get { return m_sName; }
            set { m_sName = value; }
        }

        [DataMember]
        public string FirstName
        {
            get { return m_sFirstName; }
            set { m_sFirstName = value; }
        }

        [DataMember]
        public string Email
        {
            get { return m_sEmail; }
            set { m_sEmail = value; }
        }
        
        [DataMember]
        public override Guid GuidOfAdObject
        {
            get { return m_gGuid; }
            set { m_gGuid = value; }
        }

        [DataMember]
        public override AdObjectType TypeOfAdObject
        {
            get
            {
                return e_AdObjectType;
            }
            set
            {
                e_AdObjectType = value;
            }
        }

        #endregion

        #region Constructors

        public AdUser()
        {
            KeyId = Guid.NewGuid();
        }

        #endregion

        #region Methods
        public override string InformationName
        {
            get { return m_sFirstName + " " + m_sName; }
        }
        #endregion
    }


    /// <summary>
    /// This class represents a LDAP Group
    /// </summary>
    [DataContract]
    public class AdGroup : AdObject
    {
        #region Private members
        private AdObjectType e_AdObjectType = AdObjectType.Group;
        /// <summary>
        /// The ldap guid identifier of this goup
        /// </summary>
        private Guid m_gGuid = System.Guid.NewGuid();
        /// <summary>
        /// Is the group enable?
        /// </summary>
        private bool m_bEnable = false;
        /// <summary>
        /// The name of the rgoup
        /// </summary>
        private string m_sName = string.Empty;
        
        #endregion

        #region Properties
        [DataMember]
        public bool Enable
        {
            get { return m_bEnable; }
            set { m_bEnable = value; }
        }

        [DataMember]
        public string Name
        {
            get { return m_sName; }
            set { m_sName = value; }
        }

        [DataMember]
        public override Guid GuidOfAdObject
        {
            get { return m_gGuid; }
            set { m_gGuid = value; }
        }

        [DataMember]
        public override AdObjectType TypeOfAdObject
        {
            get
            {
                return e_AdObjectType;
            }
            set
            {
                e_AdObjectType = value;
            }
        }

        #endregion

        #region Constructors

        public AdGroup()
        {
           KeyId = Guid.NewGuid();
        }

        #endregion

        #region Methods
        public override string InformationName
        {
            get { return m_sName; }
        }
        #endregion

    }

}
